Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality-of-life improvements #50

Merged
merged 5 commits into from
Feb 26, 2020
Merged

Quality-of-life improvements #50

merged 5 commits into from
Feb 26, 2020

Conversation

klarh
Copy link
Collaborator

@klarh klarh commented Feb 21, 2020

This PR improves the treatment of a few relatively minor issues.

  1. Use display_id for IPython.display.display calls in Scene.show() for many backends. This causes IPython to automatically clear the location where the scene was previously displayed.
  2. Automatically broadcast quantities that have a size of 1 in mesh.unfoldProperties. This should fix most of the confusion cases when only one particle gets drawn (see pythreejs backend not replicating properties #11), although it isn't the most elegant solution.
  3. Add ability to index Scene objects by integers or slices to get primitives. Part of Quality-of-life improvements #49.

Copy link
Member

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@klarh These are very nice quality-of-life improvements. In particular, broadcasting of single-element arrays will be super helpful! Please review these comments, then I think it's good to go.

Primitives can also be accessed in the order they were added to
the scene using list-like syntax::

first_prim = scene[:3]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
first_prim = scene[:3]
first_three_prims = scene[:3]

@@ -1,8 +1,20 @@
import contextlib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this import is separated from the others. Maybe combine this (no empty newline).

import matplotlib.pyplot as pp
from matplotlib.collections import PatchCollection
from ... import draw
import numpy as np

@contextlib.contextmanager
def manage_matplotlib_interactive():
import matplotlib.pyplot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already imported above -- use pp.isinteractive(), etc.

@@ -97,4 +109,7 @@ def save(self, filename):
return figure.savefig(filename, dpi=figure.dpi)

def _ipython_display_(self):
return self.show()
import IPython.display
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer imports at the top of the module unless this is a "soft" dependency.

@@ -180,7 +180,8 @@ def enable(self, name, auto_value=None, **parameters):

def show(self):
import IPython
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This imports IPython while other modules imported IPython.display.


self.assertIs(scene[0], prim0)
self.assertIs(scene[-1], prim1)
self.assertEqual(scene[:3], [prim0, prim1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to add one more test line:

Suggested change
self.assertEqual(scene[:3], [prim0, prim1])
self.assertEqual(scene[:2], [prim0, prim1])
self.assertEqual(scene[:3], [prim0, prim1])

This change calls IPython.display.display(..., display_id=<>) for many
of the types of scenes, which causes jupyter to update the scene if it
has been displayed already.
@klarh klarh force-pushed the ipython_display_id branch from 22916e7 to 467c6e5 Compare February 22, 2020 21:02
@klarh
Copy link
Collaborator Author

klarh commented Feb 22, 2020

Good suggestions, thanks @bdice!

This should make the broadcasting behavior of the various backends
more consistent.
@klarh klarh merged commit 50597ae into master Feb 26, 2020
@klarh klarh deleted the ipython_display_id branch February 26, 2020 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants